// components/bulletin/bulletin.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    bulletinList: {
      type: Object,
      value: {}
    }
  },

  lifetimes: {
    // 在组件实例进入页面节点树时执行
    attached: function () {
      this.setData({
        scale: app.globalData.scale
      })
      this.rollBullentin();
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    active: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /* 滚动公告栏 */
    rollBullentin() {
      let time = setInterval(() => {
        let nub = this.data.active
        let length = this.data.bulletinList.newsList.length;
        if ((nub + 1) >= length) {
          nub = 0;
        } else {
          nub++;
        }
        this.setData({
          active: nub
        })
      }, 3000)
    },

    //点击打开公告弹窗
    onClickBulletin(e) {
      this.triggerEvent('DialogShow',e.currentTarget.dataset.text)
    }
  }
})
